'use strict';
const getNumberValue = function (value) {
    let numberValue = Number(value);
    return isNaN(numberValue) ? 0 : numberValue;
}
module.exports = app => {
const { STRING, INTEGER, TEXT, DATE, DECIMAL } = app.Sequelize;
    return app.model.define(
        'OrderUser',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            order_id: STRING,
            cycle_id: INTEGER,
            nickname: STRING,
            phone: STRING,
            price: {
                type: DECIMAL(10, 2),
                get() {
                    return getNumberValue(this.getDataValue('price'));
                }
            },
            is_adult: INTEGER,
        },
        {
            tableName: 'order_user',
            timestamps: true, // 启用时间戳(createdAt, updatedAt)
            updatedAt: 'updated_time', // 不想要 updatedAt
            createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
        }
    )
};
